/*
**************************************************************************************
*Myriad Engine                                                                       *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
package leola.frontend.parsers;

import leola.ast.ASTNode;
import leola.ast.FuncDefExpr;
import leola.ast.Stmt;
import leola.frontend.LeolaParser;
import leola.frontend.Token;

/**
 * @author Tony
 *
 */
public class FuncDefExprParser extends ExprParser {
	
	/**
	 * @param parser
	 */
	public FuncDefExprParser(LeolaParser parser) {
		super(parser);
	}

	/* (non-Javadoc)
	 * @see leola.frontend.parsers.ExprParser#parse(leola.frontend.Token)
	 */
	@Override
	public ASTNode parse(Token token) throws Exception {
		Token next = this.nextToken(); // eat the DEF token					
		
		/* parse the parameter listings */		
		String[] parameters = ParserUtils.parseParameterListings(this, next);
		
		/* now parse the body */
		StmtParser parser = new StmtParser(this);
		Stmt body = (Stmt)parser.parse(currentToken());
		
		FuncDefExpr defExpr = new FuncDefExpr(body, parameters);
		setLineNumber(defExpr, currentToken());
		return defExpr;		
	}
}
